using System;
using FireStarterModeller.BO;
using Habanero.BO;

namespace Firestarter.DB.Schema.Logic
{
    public class DBTypeConverter
    {
        private readonly BusinessObjectCollection<TypeMapping> _typeMappings;

        public DBTypeConverter(BusinessObjectCollection<TypeMapping> typeMappings)
        {
            _typeMappings = typeMappings;
        }

        public BusinessObjectCollection<TypeMapping> TypeMappings
        {
            get { return _typeMappings; }
        }

        public string Convert(string fromType)
        {
            TypeMapping foundMapping = _typeMappings.Find(mapping => String.Compare(mapping.FromType, fromType, true) == 0);
            if (foundMapping != null) return foundMapping.ToType;
            return fromType;
        }
    }
}